****Download the 2016, 2018, and 2020 Congressional Election Studies*****
*****MAKE SURE TO INSERT PATH TO WHERE THE DATA IS LOCATED********

use "INSERT PATH\CCES16_Common_OUTPUT_Feb2018_VV.dta" 

gen state="."			
replace state=	"NH"	if inputstate==	33
replace state=	"LA"	if inputstate==	22
replace state=	"MO"	if inputstate==	29
replace state=	"AL"	if inputstate==	1
replace state=	"CO"	if inputstate==	8
replace state=	"TX"	if inputstate==	48
replace state=	"PA"	if inputstate==	42
replace state=	"GA"	if inputstate==	13
replace state=	"HI"	if inputstate==	15
replace state=	"FL"	if inputstate==	12
replace state=	"KS"	if inputstate==	20
replace state=	"NJ"	if inputstate==	34
replace state=	"NY"	if inputstate==	36
replace state=	"CA"	if inputstate==	6
replace state=	"MA"	if inputstate==	25
replace state=	"ME"	if inputstate==	23
replace state=	"MD"	if inputstate==	24
replace state=	"NC"	if inputstate==	37
replace state=	"MI"	if inputstate==	26
replace state=	"OR"	if inputstate==	41
replace state=	"MT"	if inputstate==	30
replace state=	"AZ"	if inputstate==	4
replace state=	"WA"	if inputstate==	53
replace state=	"VA"	if inputstate==	51
replace state=	"SC"	if inputstate==	45
replace state=	"AR"	if inputstate==	5
replace state=	"CT"	if inputstate==	9
replace state=	"TN"	if inputstate==	47
replace state=	"NV"	if inputstate==	32
replace state=	"IL"	if inputstate==	17
replace state=	"WV"	if inputstate==	54
replace state=	"OK"	if inputstate==	40
replace state=	"IN"	if inputstate==	18
replace state=	"WI"	if inputstate==	55
replace state=	"OH"	if inputstate==	39
replace state=	"UT"	if inputstate==	49
replace state=	"WY"	if inputstate==	56
replace state=	"DC"	if inputstate==	11
replace state=	"ID"	if inputstate==	16
replace state=	"MN"	if inputstate==	27
replace state=	"NE"	if inputstate==	31
replace state=	"AK"	if inputstate==	2
replace state=	"KY"	if inputstate==	21
replace state=	"RI"	if inputstate==	44
replace state=	"IA"	if inputstate==	19
replace state=	"NM"	if inputstate==	35
replace state=	"SD"	if inputstate==	46
replace state=	"ND"	if inputstate==	38
replace state=	"VT"	if inputstate==	50
replace state=	"MS"	if inputstate==	28
replace state=	"DE"	if inputstate==	10

gen congress=114
gen district=cdid113

gen approvehouserep=CC16_320f
recode approvehouserep 1=4 2=3 3=2 4=1 5/9=.

gen female=gender
recode female 1=0 2=1 8/9=.

gen age=2016-birthyr

gen education=educ
recode educ 1=8 2=12 3/4=14 5=16 6=18

gen income=faminc
recode income 1=10 2=20 3=30 4=40 5=50 6=60 7=70 8=80 9=100 10=120 11=150 12=200 13=250 14=350 15=500 16=600 97=. 98/99=.


gen ideology=ideo5
recode ideology 6/9=.

gen democrat=pid3
recode democrat 1=1 2=0 3=0 4/9=0

gen republican=pid3
recode republican 1=0 2=1 3/9=0

gen independent=pid3
recode independent 1=0 2=0 3=1 4/9=0

gen s7pointpid=pid7
recode s7pointpid 8=.

gen white=race 
recode white 1=1 2/99=0

gen raceconsscale1=CC16_422d
gen raceconsscale2=CC16_422f
recode raceconsscale2 1=5 2=4 3=3 4=2 5=1

gen raceconsscaleall=raceconsscale1+raceconsscale2

keep state district congress approvehouserep female age education income ideology democrat republican s7pointpid white raceconsscaleall raceconsscale1 raceconsscale2


save "INSERT PATH\114th Congress CES.dta"
clear

use "INSERT PATH\cces18_common_vv.dta"

gen state="."			
replace state=	"NH"	if inputstate==	33
replace state=	"LA"	if inputstate==	22
replace state=	"MO"	if inputstate==	29
replace state=	"AL"	if inputstate==	1
replace state=	"CO"	if inputstate==	8
replace state=	"TX"	if inputstate==	48
replace state=	"PA"	if inputstate==	42
replace state=	"GA"	if inputstate==	13
replace state=	"HI"	if inputstate==	15
replace state=	"FL"	if inputstate==	12
replace state=	"KS"	if inputstate==	20
replace state=	"NJ"	if inputstate==	34
replace state=	"NY"	if inputstate==	36
replace state=	"CA"	if inputstate==	6
replace state=	"MA"	if inputstate==	25
replace state=	"ME"	if inputstate==	23
replace state=	"MD"	if inputstate==	24
replace state=	"NC"	if inputstate==	37
replace state=	"MI"	if inputstate==	26
replace state=	"OR"	if inputstate==	41
replace state=	"MT"	if inputstate==	30
replace state=	"AZ"	if inputstate==	4
replace state=	"WA"	if inputstate==	53
replace state=	"VA"	if inputstate==	51
replace state=	"SC"	if inputstate==	45
replace state=	"AR"	if inputstate==	5
replace state=	"CT"	if inputstate==	9
replace state=	"TN"	if inputstate==	47
replace state=	"NV"	if inputstate==	32
replace state=	"IL"	if inputstate==	17
replace state=	"WV"	if inputstate==	54
replace state=	"OK"	if inputstate==	40
replace state=	"IN"	if inputstate==	18
replace state=	"WI"	if inputstate==	55
replace state=	"OH"	if inputstate==	39
replace state=	"UT"	if inputstate==	49
replace state=	"WY"	if inputstate==	56
replace state=	"DC"	if inputstate==	11
replace state=	"ID"	if inputstate==	16
replace state=	"MN"	if inputstate==	27
replace state=	"NE"	if inputstate==	31
replace state=	"AK"	if inputstate==	2
replace state=	"KY"	if inputstate==	21
replace state=	"RI"	if inputstate==	44
replace state=	"IA"	if inputstate==	19
replace state=	"NM"	if inputstate==	35
replace state=	"SD"	if inputstate==	46
replace state=	"ND"	if inputstate==	38
replace state=	"VT"	if inputstate==	50
replace state=	"MS"	if inputstate==	28
replace state=	"DE"	if inputstate==	10

gen congress=115
gen district=cdid115

gen approvehouserep=CC18_311a
recode approvehouserep 1=4 2=3 3=2 4=1 5/9=.

gen female=gender
recode female 1=0 2=1 8/9=.

gen age=2018-birthyr

gen education=educ
recode educ 1=8 2=12 3/4=14 5=16 6=18

gen income=faminc
recode income 1=10 2=20 3=30 4=40 5=50 6=60 7=70 8=80 9=100 10=120 11=150 12=200 13=250 14=350 15=500 16=600 97=. 98/99=.


gen ideology=ideo5
recode ideology 6/9=.

gen democrat=pid3
recode democrat 1=1 2=0 3=0 4/9=0

gen republican=pid3
recode republican 1=0 2=1 3/9=0

gen independent=pid3
recode independent 1=0 2=0 3=1 4/9=0

gen s7pointpid=pid7
recode s7pointpid 8=.

gen white=race 
recode white 1=1 2/99=0

gen raceconsscale1=CC18_422a
gen raceconsscale2=CC18_422b
recode raceconsscale2 1=5 2=4 3=3 4=2 5=1

gen raceconsscaleall=raceconsscale1+raceconsscale2

keep state district congress approvehouserep female age education income ideology democrat republican s7pointpid white raceconsscaleall raceconsscale1 raceconsscale2

save "INSERT PATH\115th Congress CES.dta"

clear

use "INSERT PATH\CES20_Common_OUTPUT_vv.dta"

gen state="."			
replace state=	"NH"	if inputstate==	33
replace state=	"LA"	if inputstate==	22
replace state=	"MO"	if inputstate==	29
replace state=	"AL"	if inputstate==	1
replace state=	"CO"	if inputstate==	8
replace state=	"TX"	if inputstate==	48
replace state=	"PA"	if inputstate==	42
replace state=	"GA"	if inputstate==	13
replace state=	"HI"	if inputstate==	15
replace state=	"FL"	if inputstate==	12
replace state=	"KS"	if inputstate==	20
replace state=	"NJ"	if inputstate==	34
replace state=	"NY"	if inputstate==	36
replace state=	"CA"	if inputstate==	6
replace state=	"MA"	if inputstate==	25
replace state=	"ME"	if inputstate==	23
replace state=	"MD"	if inputstate==	24
replace state=	"NC"	if inputstate==	37
replace state=	"MI"	if inputstate==	26
replace state=	"OR"	if inputstate==	41
replace state=	"MT"	if inputstate==	30
replace state=	"AZ"	if inputstate==	4
replace state=	"WA"	if inputstate==	53
replace state=	"VA"	if inputstate==	51
replace state=	"SC"	if inputstate==	45
replace state=	"AR"	if inputstate==	5
replace state=	"CT"	if inputstate==	9
replace state=	"TN"	if inputstate==	47
replace state=	"NV"	if inputstate==	32
replace state=	"IL"	if inputstate==	17
replace state=	"WV"	if inputstate==	54
replace state=	"OK"	if inputstate==	40
replace state=	"IN"	if inputstate==	18
replace state=	"WI"	if inputstate==	55
replace state=	"OH"	if inputstate==	39
replace state=	"UT"	if inputstate==	49
replace state=	"WY"	if inputstate==	56
replace state=	"DC"	if inputstate==	11
replace state=	"ID"	if inputstate==	16
replace state=	"MN"	if inputstate==	27
replace state=	"NE"	if inputstate==	31
replace state=	"AK"	if inputstate==	2
replace state=	"KY"	if inputstate==	21
replace state=	"RI"	if inputstate==	44
replace state=	"IA"	if inputstate==	19
replace state=	"NM"	if inputstate==	35
replace state=	"SD"	if inputstate==	46
replace state=	"ND"	if inputstate==	38
replace state=	"VT"	if inputstate==	50
replace state=	"MS"	if inputstate==	28
replace state=	"DE"	if inputstate==	10

gen congress=116
gen district=cdid116

gen approvehouserep=CC20_320f
recode approvehouserep 1=4 2=3 3=2 4=1 5/9=.

gen female=gender
recode female 1=0 2=1 8/9=.

gen age=2020-birthyr

gen education=educ
recode educ 1=8 2=12 3/4=14 5=16 6=18

gen income=faminc
recode income 1=10 2=20 3=30 4=40 5=50 6=60 7=70 8=80 9=100 10=120 11=150 12=200 13=250 14=350 15=500 16=600 97=. 98/99=.


gen ideology=ideo5
recode ideology 6/9=.

gen democrat=pid3
recode democrat 1=1 2=0 3=0 4/9=0

gen republican=pid3
recode republican 1=0 2=1 3/9=0

gen independent=pid3
recode independent 1=0 2=0 3=1 4/9=0

gen s7pointpid=pid7
recode s7pointpid 8=.

gen white=race 
recode white 1=1 2/99=0

gen raceconsscale1=CC20_440a
gen raceconsscale2=CC20_440b
recode raceconsscale2 1=5 2=4 3=3 4=2 5=1

gen raceconsscaleall=raceconsscale1+raceconsscale2


keep state district congress approvehouserep female age education income ideology democrat republican s7pointpid white raceconsscaleall raceconsscale1 raceconsscale2
save "INSERT PATH\116th Congress CES.dta"
append using "INSERT PATH\114th Congress CES.dta"
append using "INSERT PATH\115th Congress CES.dta"

destring district, replace
save "INSERT PATH\Individual Data.dta", replace

clear

***Make Sure to Download Rep Level Data*****
import delimited "INSERT PATH\Rep Level Data.csv", bindquote(strict) 

merge 1:m state district congress using "INSERT PATH \Individual Data.dta"

gen sameparty=0
replace sameparty=1 if democrat==1 & democratrep==1
replace sameparty=1 if republican==1 & democratrep==0


xtset icpsr
***Table 1 Replication****
xtologit approvehouserep skintone i.congress femalerep majorityparty democratrep partyleader committeechair totalbills dwnom1 female age income education ideology democrat republican if white==1 & sameparty==0 & whiterep==0
xtologit approvehouserep skintone i.congress femalerep majorityparty democratrep partyleader committeechair totalbills dwnom1 female age income education ideology democrat republican if white==1 & sameparty==1 & whiterep==0


***Table 2 Replication***
xtologit approvehouserep skintone i.congress femalerep majorityparty democratrep partyleader committeechair totalbills dwnom1 female age income education ideology democrat republican if white==1 & sameparty==0 & whiterep==0 & raceconsscaleall>5
xtologit approvehouserep skintone i.congress femalerep majorityparty democratrep partyleader committeechair totalbills dwnom1 female age income education ideology democrat republican if white==1 & sameparty==0 & whiterep==0 & raceconsscaleall<6
xtologit approvehouserep skintone i.congress femalerep majorityparty democratrep partyleader committeechair totalbills dwnom1 female age income education ideology democrat republican if white==1 & sameparty==1 & whiterep==0 & raceconsscaleall>5
xtologit approvehouserep skintone i.congress femalerep majorityparty democratrep partyleader committeechair totalbills dwnom1 female age income education ideology democrat republican if white==1 & sameparty==1 & whiterep==0 & raceconsscaleall<6
